package com.me.libgdx_test;

import java.util.ArrayList;
import java.util.Collections;

import com.badlogic.gdx.graphics.g2d.Sprite;

public class ClassAnimationSequence {
	private String name;
	private ArrayList<animation_frames> frames;
	private ClassLogDisplay logger;
	ClassAnimationSequence(String name){
		logger = new ClassLogDisplay("ClassAnimationSequence");
		frames = new ArrayList<animation_frames>();
		logger.print("Sequence Name: " + name);
		this.name = name;
	}
	public void add_frame(String frame, Sprite sprite){
		String frame_index = frame.substring(frame.lastIndexOf("_")+1, frame.lastIndexOf("a"));
		logger.print("Adding frame index: " + frame_index);
		int index = Integer.valueOf(frame_index);
		logger.print("Index: " + index);
		frames.add(new animation_frames(index, frame, sprite));
	}
	public String get_name(){
		return name;
	}
	public ArrayList<String> get_sequence_strings(){
		ArrayList<String> sequence_strings = new ArrayList<String>();
		for(animation_frames frame:frames){
			sequence_strings.add(frame.name);
		}
		return sequence_strings;
	}
	public ArrayList<Sprite> get_sequence_sprites(){
		ArrayList<Sprite> sequence_sprites = new ArrayList<Sprite>();
		for(animation_frames frame:frames){
			sequence_sprites.add(frame.sprite);
		}
		return sequence_sprites;
	}
	public void sort_frames(){
		ArrayList<animation_frames> temp_frames = new ArrayList<animation_frames>();
		for(int i = 0; i < frames.size(); i++){
			for(animation_frames frame:frames){
				if(frame.index == (i+1)){
					temp_frames.add(frame);
				}
			}
		}
		frames = temp_frames;
	}
	class animation_frames{
		int index;
		String name;
		Sprite sprite;
		animation_frames(int index, String name, Sprite sprite){
			this.index = index;
			this.name = name;
			this.sprite = new Sprite(sprite);
		}
	}
}
